using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace Xfinity.Rendering.Lighting
{
    public class PointLight : ILight
    {
        #region Position
        private Vector3 position;

        /// <summary>
        /// Position.
        /// </summary>
        public Vector3 Position
        {
            [System.Diagnostics.DebuggerStepThroughAttribute]
            get { return position; }
            [System.Diagnostics.DebuggerStepThroughAttribute]
            set { position = value; }
        }
        #endregion
        #region Radiance
        private float radiance;

        /// <summary>
        /// Intensity.
        /// </summary>
        public float Radiance
        {
            [System.Diagnostics.DebuggerStepThroughAttribute]
            get { return radiance; }
            [System.Diagnostics.DebuggerStepThroughAttribute]
            set { radiance = value; }
        }
        #endregion
        #region Colour
        private Vector3 colour;

        /// <summary>
        /// Colour.
        /// </summary>
        public Vector3 Colour
        {
            [System.Diagnostics.DebuggerStepThroughAttribute]
            get { return colour; }
            [System.Diagnostics.DebuggerStepThroughAttribute]
            set { colour = value; }
        }
        #endregion
        #region Enabled
        private bool enabled;

        /// <summary>
        /// Enabled.
        /// </summary>
        public bool Enabled
        {
            [System.Diagnostics.DebuggerStepThroughAttribute]
            get { return enabled; }
            [System.Diagnostics.DebuggerStepThroughAttribute]
            set { enabled = value; }
        }
        #endregion

        public PointLight()
        {
            position = Vector3.Zero;
            radiance = 1;
            colour = Vector3.One;
            enabled = true;
        }
        public PointLight(Vector3 position, Vector3 colour, float radiance, bool enabled)
        {
            this.position = position;
            this.colour = colour;
            this.radiance = radiance;
            this.enabled = enabled;
        }

        /// <summary>
        /// Gets the received colour at a point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>The colour.</returns>
        public Vector3 GetColourAtPoint(Vector3 point)
        {
            float distance = (point - position).Length();
            float divisor = distance + radiance;
            return colour * ((radiance / (divisor * divisor)) * radiance * radiance);
        }
    }
}
